﻿using Heng.Elements.Core.Model.Repository.EF.Infrastructure.Repositories;
using Heng.Elements.ERD.Model.Entities;
using Heng.Elements.ERD.Model.Repositories;
using Heng.Elements.ERD.Model.Repository.EF.Contexts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Heng.Elements.ERD.Model.Repository.EF.Repositories
{
    public class DomainEntityRelationRepository : EFEntityRepository<DomainEntityRelation, CoreEntities>, IDomainEntityRelationRepository
    {
        public IEnumerable<DomainEntityRelation> GetByEntity(long entityId)
        {
            var relations = from rel in this.ContextFacade.DbContext.DomainEntityRelations.
                                Include("DomainEntityA").
                                Include("DomainEntityB").
                                Include("DomainEntityRelationAttributeA").
                                Include("DomainEntityRelationAttributeB")
                            where rel.DomainEntityAId == entityId || rel.DomainEntityBId == entityId
                                && rel.Status == 0
                            select rel;

            return relations.ToList();
        }
    }
}
